import 'package:flutter/material.dart';

class Message extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return _Message();
  }
}

class _Message extends State<Message> {
  final List list = [];

  @override
  void initState() {
    super.initState();

    for (int i = 0; i < 100; i++) {
      list.add({
        "key": i,
        "avatar":
            "https://q2.itc.cn/q_70/images03/20240807/9efb7d3e616440c6ab1d7e1d9b9be14f.jpeg",
        "title": "测试测试",
        "desc": "测试数据水电费水电费水电费",
        "time": "星期四",
        "badge": 10
      });
    }
  }

  Widget item(int index) {
    var row = list[index];

    return Stack(
      children: [
        Padding(
          padding: const EdgeInsets.fromLTRB(10, 20, 10, 20),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Container(
                width: 55,
                height: 45,
                child: Stack(
                  children: [
                    Positioned(
                      top: 10,
                      child: Container(
                        width: 40,
                        height: 40,
                        decoration: BoxDecoration(
                            borderRadius: BorderRadius.circular(10)),
                        child: Image.network(row["avatar"]),
                      ),
                    ),
                    Positioned(
                        top: 0,
                        right: 0,
                        child: Container(
                          padding: EdgeInsets.only(left: 7, right: 7),
                          height: 20,
                          decoration: BoxDecoration(
                              color: Colors.red,
                              borderRadius: BorderRadius.circular(10)),
                          child: Center(
                            child: Text(
                              "2",
                              style:
                                  TextStyle(fontSize: 11, color: Colors.white),
                            ),
                          ),
                        ))
                  ],
                ),
              ),
              const SizedBox(
                width: 20,
              ),
              Expanded(
                  flex: 1,
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            Text(
                              row["title"],
                              style: const TextStyle(
                                  fontSize: 20, color: Colors.black),
                            ),
                            Text(
                              row["time"],
                              style: const TextStyle(
                                  fontSize: 12,
                                  color: Color.fromARGB(255, 100, 100, 100)),
                            )
                          ]),
                      Text(
                        row["desc"],
                        style: const TextStyle(
                            color: Color.fromARGB(255, 100, 100, 100)),
                      ),
                    ],
                  ))
            ],
          ),
        ),
        Positioned(
          bottom: 0,
          right: 0,
          left: 60,
          child: index < list.length - 1 ? Divider() : SizedBox(),
        )
      ],
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        leading: null,
        title: const Text(
          "聊天",
          style: TextStyle(
            color: Colors.black,
            fontSize: 20,
          ),
          ),
        centerTitle: true,
      ),
      body: ListView.builder(
          padding: const EdgeInsets.fromLTRB(0, 0, 0, 30),
          itemCount: list.length,
          itemBuilder: (context, index) {
            return item(index);
          }),
    );
  }
}
